<%
/**
 * second wizard page / tab
 *
 * @author	Jeroen Wesbeek <work@osx.eu>
 * @package AjaxFlow
 */
%>
<script type="text/javascript" >
 function remappingBean(){
	    $("#add_more_family").click(function(e){
	        e.preventDefault();
	        addFamiglia('','','');	
	    });	
	

    	    <g:if test="${customer?.families}">
    		    <g:each in="${customer.families}" var="item">
    		    	<g:if test="${item.type.value}">
    		    		//alert('${item.job}')
    		    		addFamiglia('${item.type.value}','${item.job}','${item.ran}');	
    		    	 </g:if>	
    			</g:each>
    	    </g:if>	 
 }
 
	function addFamiglia(tip,job,ran){
		//alert(tip)
	        var next = parseInt($("#count_family").val());
	        var addto = "#new_row_family_" + (next);
	        var divRow=$('<div class="row" id="new_row_family_' + (next+1)+'"></div>');
	        var divColBtn=$('<div class="col-sm-1"></div>');
	        var removeButton = $('<button type="button" class="btn btn-danger btn-md " id="remove_family_' + (next+1) + '" ><i class="glyphicon glyphicon-trash"></i></button>	');
	        removeButton.click(function(e){
                e.preventDefault();
                var fieldNum = this.id.charAt(this.id.length-1);
                var fieldID = "#new_row_family_" + fieldNum;
                $(fieldID).remove();
                var next = parseInt($("#count_family").val());
                next = (next -1);
                $("#count_family").val(next);  
            }); 
	        divColBtn.append(removeButton)
	        divRow.append(divColBtn);
	        var familyType=$('<div class="col-sm-5"></div>');
	        var ft = $('<div class="form-group"></div>');
	        var selectContainer=$('<div class="input-group" ><span class="input-group-addon"><i class="fa fa-briefcase fa-lg fa-fw">'+
	    	        '</i></span></div>');  
	        var allOption=$('<select id="familyType" name="familyType" class="form-control"/>');
	        
	        <g:each in="${com.macrosolution.exdebito.FamilyType?.list()}" var="a" status="i">
	        var divOption${i}=null
	        if('${a.value}' == tip){
	        	divOption${i}=$('<option value="${a.value}" selected >${a.value}</option>');
		        }else{
		        	divOption${i}=$('<option value="${a.value}" >${a.value}</option>');
			}
	        	 
	        	allOption.append(divOption${i});
	        </g:each>
	        selectContainer.append(allOption);
	        ft.append(selectContainer);	
			familyType.append(ft);
	        divRow.append(familyType);
	        
	        var familyType2=$('<div class="col-sm-5 col-md-offset-1"><div class="form-group"><div class="input-group">'+
	    	        			'<span class="input-group-addon"><i class="fa  fa-user fa-lg fa-fw"></i></span>'+
	    	        				'<input style="width:100%" placeholder="Impiego" class="form-control input-md" name="job" id="job" value="'+((job!=null)?job:'')+'">'+
	    	        			'</div></div></div><div class="col-sm-5 col-md-offset-1"><div class="form-group">'+
	    	        			'<div class="input-group"><span class="input-group-addon"><i class="fa fa-eur fa-lg fa-fw"></i></span>'+
	    	        				'<input class="form-control input-md currency" placeholder="Reddito Annuo Netto" type="text" name="ran" id="ran"  value="'+((ran!=null)?ran:'')+'">'+
	    	        			'</div></div></div>');
	        divRow.append(familyType2);
	        next = next + 1;
	        $(addto).after(divRow);
	        $("#count_family").val(next);
	        currencyFormatter();
		} 
 	
</script>
<af:page>
<div class="alert alert-danger fade in" id="validity_label"></div>
<g:if test="${interview}">
<div class="col-sm-3 col-md-offset-9">
	<h3>Intervista : <exdutility:number_interview value="${interview?.id }"/></h3>
</div>
</g:if>

<h3>Nucleo Familiare</h3>
<div class="row">
	<div class="col-sm-5 col-md-offset-1">
		<div class="form-group">
			<div class="input-group">
				<span class="input-group-addon"><i class="fa fa-user fa-lg fa-fw"></i></span>
				<input class="form-control input-md" placeholder="Nucleo Familiare" type="text" 
					name="familiesNumber" id="familiesNumber" value="${customer?.familiesNumber}"
				/>
			</div>
		</div>
	</div>
</div>



</br>

<h3>Inserire Info sul Familiare&nbsp;&nbsp;&nbsp;
	<a >  
		<button type="button" class="btn btn-info btn-md" id="add_more_family" style="margin-bottom:12px">
			<i class="fa fa-plus-circle"></i>
		</button>
	</a>
</h3>
<input type="hidden" name="count_family" id="count_family" value="0" />
<div id="new_row_family_0"></div>

</br></br></br>
<div style="border-top: 2px solid #006DBA; padding-top: 2px;"></div>
</af:page>
